package com.dower.clothing.controller;

import java.util.List;

import com.dower.common.annotation.Log;
import com.dower.common.core.controller.BaseController;
import com.dower.common.core.domain.AjaxResult;
import com.dower.common.core.page.TableDataInfo;
import com.dower.common.enums.BusinessType;
import com.dower.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.dower.clothing.domain.FinaPurchaseGoods;
import com.dower.clothing.service.IFinaPurchaseGoodsService;

/**
 * 进货商品Controller
 * 
 * @author dower
 * @date 2020-09-02
 */
@Controller
@RequestMapping("/clothing/goods")
public class FinaPurchaseGoodsController extends BaseController
{
    private String prefix = "clothing/goods";

    @Autowired
    private IFinaPurchaseGoodsService finaPurchaseGoodsService;

    @RequiresPermissions("clothing:goods:view")
    @GetMapping()
    public String goods()
    {
        return prefix + "/goods";
    }

    /**
     * 查询进货商品列表
     */
    @RequiresPermissions("clothing:goods:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FinaPurchaseGoods finaPurchaseGoods)
    {
        startPage();
        List<FinaPurchaseGoods> list = finaPurchaseGoodsService.selectFinaPurchaseGoodsList(finaPurchaseGoods);
        return getDataTable(list);
    }

    /**
     * 导出进货商品列表
     */
    @RequiresPermissions("clothing:goods:export")
    @Log(title = "进货商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FinaPurchaseGoods finaPurchaseGoods)
    {
        List<FinaPurchaseGoods> list = finaPurchaseGoodsService.selectFinaPurchaseGoodsList(finaPurchaseGoods);
        ExcelUtil<FinaPurchaseGoods> util = new ExcelUtil<FinaPurchaseGoods>(FinaPurchaseGoods.class);
        return util.exportExcel(list, "goods");
    }

    /**
     * 新增进货商品
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存进货商品
     */
    @RequiresPermissions("clothing:goods:add")
    @Log(title = "进货商品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FinaPurchaseGoods finaPurchaseGoods)
    {
        return toAjax(finaPurchaseGoodsService.insertFinaPurchaseGoods(finaPurchaseGoods));
    }

    /**
     * 修改进货商品
     */
    @GetMapping("/edit/{purchaseGoodsId}")
    public String edit(@PathVariable("purchaseGoodsId") Long purchaseGoodsId, ModelMap mmap)
    {
        FinaPurchaseGoods finaPurchaseGoods = finaPurchaseGoodsService.selectFinaPurchaseGoodsById(purchaseGoodsId);
        mmap.put("finaPurchaseGoods", finaPurchaseGoods);
        return prefix + "/edit";
    }

    /**
     * 修改保存进货商品
     */
    @RequiresPermissions("clothing:goods:edit")
    @Log(title = "进货商品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FinaPurchaseGoods finaPurchaseGoods)
    {
        return toAjax(finaPurchaseGoodsService.updateFinaPurchaseGoods(finaPurchaseGoods));
    }

    /**
     * 删除进货商品
     */
    @RequiresPermissions("clothing:goods:remove")
    @Log(title = "进货商品", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(finaPurchaseGoodsService.deleteFinaPurchaseGoodsByIds(ids));
    }
}
